package ServiceDashBoard

import (
	"github.com/go-echarts/go-echarts/v2/charts"
	"github.com/go-echarts/go-echarts/v2/opts"
	"github.com/go-echarts/go-echarts/v2/types"
	"log"
	"math/rand"
	"os"
	"ustcLab/conf"
)


func Show() {

	line := charts.NewLine()
	line.SetGlobalOptions(
		charts.WithInitializationOpts(opts.Initialization{
			PageTitle:       "",
			Width:           "500px",
			Height:          "500px",
			BackgroundColor: "",
			ChartID:         "",
			AssetsHost:      "",
			Theme:           types.ThemeChalk,
		}))
	line.SetXAxis([]string{"1", "2", "3"}).
		AddSeries("C A", generateLineItems()).
		AddSeries("C B", generateLineItems()).
		SetSeriesOptions(charts.WithLineChartOpts(opts.LineChart{
			Stack:        "",
			Smooth:       true,
			Step:         false,
			XAxisIndex:   0,
			YAxisIndex:   0,
			ConnectNulls: false,
		}))

	pageFile, err := os.Create(conf.GraphPath)
	defer pageFile.Close()
	if err != nil {
		log.Println(err)
	}

	line.Render(pageFile)
}

// generate random data for line chart
func generateLineItems() []opts.LineData {
	items := make([]opts.LineData, 0)
	for i := 0; i < 7; i++ {
		items = append(items, opts.LineData{Value: rand.Intn(300)})
	}
	return items
}
